package site.microkang.house.service.publicity;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import site.microkang.house.mapper.publicity.HouseProjectPublicityMapper;
import site.microkang.house.model.publicity.entity.HouseProjectPublicityEntity;

import java.util.List;

/**
 * @author liukang
 * @date 2021/3/15 14:30
 */
@Service
@Transactional(readOnly = true)
public class HouseProjectPublicityService {

    @Autowired(required = false)
    private HouseProjectPublicityMapper houseProjectPublicityMapper;

    /**
     * 获取所有住房数据
     * @return
     */
    public List<HouseProjectPublicityEntity> getAll() {
        List<HouseProjectPublicityEntity> list = houseProjectPublicityMapper.getAll();
        return list;
    }

    @Transactional(readOnly = false)
    public int externalDataInsert(HouseProjectPublicityEntity entity) {
        List<HouseProjectPublicityEntity> uniqueEntity = houseProjectPublicityMapper.getUniqueEntity(entity);
        if (uniqueEntity != null && uniqueEntity.size() != 0) {
            HouseProjectPublicityEntity houseProjectPublicityEntity = uniqueEntity.get(0);
            int update = houseProjectPublicityMapper.updateById(houseProjectPublicityEntity);
            return update;
        }
        int insert = houseProjectPublicityMapper.insert(entity);
        return insert;
    }
}
